﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace CodeBuilder.DBM
{
    class DBManager
    {
        private static string s = "(local)";
        private static string u = "sa";
        private static string p = "0";
        private static string d = "master";
        private static string cs = "server=" + s + ";uid=" + u + ";pwd=" + p + ";database=" + d;
        // .net 中的 string 也是对象？
        private static SqlConnection sc = BuildSqlConnection();
        
        public static string connectionString
        {
            get
            {
                return cs;
            }
            set
            {
                if (value != null)
                {
                    cs = value;
                    //sc = BuildSqlConnection();
                }
            }
        }

        public static SqlConnection sqlConn
        {
            get
            {
                sc = BuildSqlConnection();
                return sc;
            }
        }

        private static SqlConnection BuildSqlConnection()
        {
            return new SqlConnection(cs);
        }

        public static string server
        {
            get
            {
                return s;
            }
            set
            {
                s = value;
                cs = "server=" + s + ";uid=" + u + ";pwd=" + p + ";database=" + d;
            }
        }

        public static string uid
        {
            get
            {
                return u;
            }
            set
            {
                u = value;
                cs = "server=" + s + ";uid=" + u + ";pwd=" + p + ";database=" + d;
            }
        }

        public static string pwd
        {
            get
            {
                return p;
            }
            set
            {
                p = value;
                cs = "server=" + s + ";uid=" + u + ";pwd=" + p + ";database=" + d;
            }
        }

        public static string database
        {
            get
            {
                return d;
            }
            set
            {
                d = value;
                cs = "server=" + s + ";uid=" + u + ";pwd=" + p + ";database=" + d;
            }
        }
    }
}
